package com.cskaoyan.controller.admin;

import com.cskaoyan.model.admin.vo.BaseRespVo;
import com.cskaoyan.model.admin.vo.MallConfigRespVO;
import com.cskaoyan.model.admin.vo.SelectWxVO;
import com.cskaoyan.service.admin.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName: ConfigController
 * @Author: WangEnzhao
 * @Description: 配置管理模块
 * @CreateTime: 2021/11/20:14:00
 */
@RequestMapping("admin/config")
@RestController
public class ConfigController {

    @Autowired
    ConfigService configService;

    /**
    * @Author: WangEnzhao
    * @Description: 商场配置
    * @CreateTime:
    * @Param:
    * @return:
    **/
    @GetMapping("mall")
    public BaseRespVo selectMallConfig(){
        MallConfigRespVO mallConfigRespVO = configService.selectMallConfig();
        return BaseRespVo.ok(mallConfigRespVO);
    }

    /**
    * @Author: WangEnzhao
    * @Description: 修改商场配置
    * @CreateTime:
    * @Param:
    * @return:
    **/
    @PostMapping("mall")
    public BaseRespVo changeMallConfig(@RequestBody Map<String, String> mallConfigMap){
        int code = configService.updateMallConfig(mallConfigMap);
        if(code == 0){
            return  BaseRespVo.ok("成功");
        }
        return BaseRespVo.ok("错误");
    }

    /**
    * @Author: WangEnzhao
    * @Description: 获取express配置
    * @CreateTime:
    * @Param:
    * @return:
    **/
    @GetMapping("express")
    public BaseRespVo selectExpressConfig(){
        Map map = configService.selectExpressConfig();
        return BaseRespVo.ok(map);
    }
    /**
    * @Author: WangEnzhao
    * @Description: update Express 配置
    * @CreateTime:
    * @Param:
    * @return:
    **/
    @PostMapping("express")
    public BaseRespVo updateExpressConfig(@RequestBody Map<String, String> updateExpressMap){
        int code = configService.updateExpressConfig(updateExpressMap);
        return BaseRespVo.ok(null);
    }
    /**
     * @Author: WangEnzhao
     * @Description: 查询order配置
     * @CreateTime:
     * @Param:
     * @return:
     **/
    @GetMapping("order")
    public BaseRespVo selectOrderConfig(){
        Map map = configService.selectOrderConfig();
        return BaseRespVo.ok(map);
    }

    /**
     * @Author: WangEnzhao
     * @Description: 更新order配置
     * @CreateTime:
     * @Param:
     * @return:
     **/
    @PostMapping("order")
    public BaseRespVo updateOrderConfig(@RequestBody Map<String,String> updateOrderMap){
        configService.updateOrderConfig(updateOrderMap);
        return BaseRespVo.ok(null);
    }
    
    /**
    * @Author: WangEnzhao
    * @Description: 小程序配置查询
    * @CreateTime:
    * @Param: 
    * @return: 
    **/
    @GetMapping("wx")
    public BaseRespVo selectWx(){
        SelectWxVO selectWxVO = configService.selectWxConfig();
        return BaseRespVo.ok(selectWxVO);
    }

    /**
     * @Author: WangEnzhao
     * @Description: 小程序配置更新
     * @CreateTime:
     * @Param:
     * @return:
     **/
    @PostMapping("wx")
    public BaseRespVo updateWx(@RequestBody Map<String, String> updateWxConfigMap){
        configService.updateWxConfig(updateWxConfigMap);
        return BaseRespVo.ok(null);
    }


}
